#ifndef ITEMREFERENCEPROXY_H
#define ITEMREFERENCEPROXY_H



#include "viewutils_global.h"



#include <Item.h>



#include <QMap>
#include <QAbstractProxyModel>
#include <QPersistentModelIndex>
#include <QPointer>



class VIEWUTILSSHARED_EXPORT ItemReferenceProxy : public QAbstractProxyModel
{
    Q_OBJECT

public:

    enum DataType
    {
        DataType_FIRST = 0,

        NameData = DataType_FIRST,
        IdData,

        DataType_LAST = IdData
    };

    ItemReferenceProxy(Item* targetItem, QAbstractItemModel* sourceModel, QObject *parent = 0);


    // required abstract proxy model functions
    virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
    virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;


    // required abstract item model functions
    virtual QVariant data(const QModelIndex &proxyIndex, int role) const;

    virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
    virtual QModelIndex parent(const QModelIndex &child) const;

    virtual int rowCount(const QModelIndex &parent) const;
    virtual int columnCount(const QModelIndex &parent) const;



protected slots:

    void remap();


private:

    QMap<QPersistentModelIndex, QPersistentModelIndex> m_mapping;
    QPointer<Item> m_targetItem;

};



#endif // ITEMREFERENCEPROXY_H


